from .utils import *

# 获取作品数量Top20的导演数据 -- （导演名称，导演作品数量）
def getDirectorsData():
    directorsList = typeList1('directors')
    # 词频统计
    directorsObj = {}
    for i in directorsList:
        if directorsObj.get(i, -1) == -1:
            directorsObj[i] = 1
        else:
            directorsObj[i] = directorsObj[i] + 1
    # 获取排名前20的数据(从大到小)
    directorsObj = sorted(directorsObj.items(), key=lambda x: x[1], reverse=True)[:20]
    # 导演名称
    directors = []
    # 导演作品数量
    cnts = []
    for i in directorsObj:
        directors.append(i[0])
        cnts.append(i[1])
    return directors, cnts

# 获取参演电影数量Top20的演员数据 -- （演员名称，演员参演电影数量）
def getCastsData():
    castsList = typeList1('casts')
    # 词频统计
    castsObj = {}
    for i in castsList:
        if castsObj.get(i, -1) == -1:
            castsObj[i] = 1
        else:
            castsObj[i] = castsObj[i] + 1
    # 获取排名前20的数据(从大到小)
    castsObj = sorted(castsObj.items(), key=lambda x: x[1], reverse=True)[:20]
    # 导演名称
    casts = []
    # 导演作品数量
    nums = []
    for i in castsObj:
        casts.append(i[0])
        nums.append(i[1])
    return casts, nums

# test
# print(getDirectorsData())
# print(getCastsData())